﻿@model List<Model.ViewModel.SaleGoods>


@foreach (var goodssort in Model)
{
    <div class="btn-group" style="margin-top: 2px; margin-bottom: 2px;">

        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
            @goodssort.GoodsSortName <span class="caret"></span>
        </button>

        <div class="dropdown-menu" role="menu" style="width:300px;">
            <table class="table table-condensed table-responsive text-center">
                <thead class="bg-info">
                    <tr><td>品名</td><td>单价</td><td>数量</td></tr>
                </thead>
                <tbody>
                    @foreach (var g in @goodssort.Goods)
                    {
                        <tr>
                            <td>
                                <a href="#" onclick="Open_Modal_Sale('@g.GoodsID','@g.GoodsName','@g.MeasureUnite','@g.Quntity','@g.SalePrice')">@g.GoodsName  </a>
                            </td>
                            <td>@g.SalePrice.ToString("0.00")</td>
                            <td>
                                @g.Quntity
                            </td>
                        </tr>
                    }
                </tbody>
            </table>


        </div>
    </div>

}
@Html.Partial("Modal_Sale")
<script type="text/javascript">
    var IsSale = false;
    $('#Modal_Sale').on('hidden.bs.modal', function (e) {
        if (IsSale) {
            $("#playersDiv").load("Sale/SaleGoods");//将销售清单刷新,使数量同步
            if (SaleObject == "SaleCredit" && CreditSaleNOID != "") {

                $("#CreditSale_List").load("SaleCredit/CreditSaleTD_List?CreditSaleNOID=" + CreditSaleNOID);
                
            }
            else {

                Sale_List();
            }
        }
        //$("#playersDiv").load("Sale/SaleGoods");
    });
    function Open_Modal_Sale(GoodsID, GoodsName, MeasureUnite, Quntity, SalePrice) {
        var salep = SalePrice.match(/^\d+(?:\.\d{0,2})?/);

        $('#Modal_Sale .modal-title span:last-child').html(GoodsName);
        $('#Modal_Sale .modal-body span:eq(0)').html(GoodsName);
        $('#Modal_Sale .modal-body span:eq(1)').html(salep);
        $('#Modal_Sale .modal-body span:eq(2)').html(Quntity + MeasureUnite);
        $('#Modal_Sale .modal-body span:eq(3)').html(MeasureUnite);
        $('#Modal_Sale .modal-body span:eq(4)').html(SalePrice * 1);
        $('#Modal_Sale form [name="GoodsID"]').val(GoodsID);
        $('#Modal_Sale form [name="Sale_Quntity"]').val(1);
        $("#Modal_Sale .modal-footer span").html('');
        $('#Modal_Sale').modal('show');
    }

</script>
<script type="text/javascript">
    var CreditSaleNOID;
    var CreditRoomID;
    var SaleObject;

    function Btn_Modal_Sale() {

        //判断url中是否有CreditNOID传值，有就是挂账销售，执行
        var Request = new Object();
        Request = GetRequest(this.location.href);//转字符串
        if (Request['CreditSaleNOID'] != null && Request['CreditRoomID'] != null) {
            CreditSaleNOID = Request['CreditSaleNOID'].split("#")[0];
            CreditRoomID = Request['CreditRoomID'].split("#")[0];
            SaleObject = "SaleCredit";

        }
        else {
            SaleObject = "Sale";
        }

        var quntity = $("#Modal_Sale form input[name='Sale_Quntity']");
        if (quntity.val() != "") {

            if (valInt(quntity.val())) {
                //提交


                $.ajax({
                    type: "POST",
                    url: SaleObject + "/btn_SaleGoods",
                    data: "SaleGoodsID=" + $("#Modal_Sale form input[name='GoodsID']").val() +
                        "&SaleNumber=" + $("#Modal_Sale form input[name='Sale_Quntity']").val() +
                        "&IsExchange=" + $("#Modal_Sale form input[type='checkbox']").is(':checked') +
                        "&CreditSaleNOID=" + CreditSaleNOID +
                        "&CreditRoomID=" + CreditRoomID,
                    success: function (msg) {
                        if (msg == "ok") {
                            //alert("Data Saved: " + msg);
                            IsSale = true;
                            $("#Modal_Sale").modal('toggle');

                        }

                    }
                });
            }
            else {
                $("#Modal_Sale .modal-footer span").html('数量必须整数!');

            }


        }

        else {
            $("#Modal_Sale .modal-footer span").html('数量不能为空!');
        }

    }
</script>
